package dayPractice;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author Summerday
 */
public class Main1432棋盘挑战 {

    static int n;
    static int[] path;
    static boolean[] col, dg, udg;
    static List<int[]> res = new ArrayList<>();


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        path = new int[n + 1];

        col = new boolean[n + 1];
        dg = new boolean[2 * (n + 1)];
        udg = new boolean[2 * (n + 1)];

        dfs(1);

        for (int i = 0; i < 3; i++) {
            int[] ans = res.get(i);
            for (int j = 1; j <= n; j ++) {
                System.out.print(ans[j] + " ");
            }
            System.out.println();
        }
        System.out.println(res.size());
    }

    static void dfs(int r) {
        if (r == n + 1) {
            int[] temp = new int[path.length];
            System.arraycopy(path, 0, temp, 0, path.length);
            res.add(temp);
            return;
        }

        for (int i = 1; i <= n; i++) {
            if (!col[i] && !dg[i + r] && !udg[n - i + r]) {
                path[r] = i;
                col[i] = true;
                dg[i + r] = true;
                udg[n - i + r] = true;
                dfs(r + 1);
                col[i] = false;
                dg[i + r] = false;
                udg[n - i + r] = false;
            }
        }
    }
}
